﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Collections;

namespace B2B.Models
{
    public class SP_OrdersSent
    {
        int maDonHang;

        public int MaDonHang
        {
            get { return maDonHang; }
            set { maDonHang = value; }
        }
        int maBaoGia;

        public int MaBaoGia
        {
            get { return maBaoGia; }
            set { maBaoGia = value; }
        }
        int soLuongDat;

        public int SoLuongDat
        {
            get { return soLuongDat; }
            set { soLuongDat = value; }
        }
        double gia;

        public double Gia
        {
            get { return gia; }
            set { gia = value; }
        }
        double tongTien;

        public double TongTien
        {
            get { return tongTien; }
            set { tongTien = value; }
        }
        double daTraTruoc;

        public double DaTraTruoc
        {
            get { return daTraTruoc; }
            set { daTraTruoc = value; }
        }
        string emailNguoiNhan;

        public string EmailNguoiNhan
        {
            get { return emailNguoiNhan; }
            set { emailNguoiNhan = value; }
        }
        string ngayLap;

        public string NgayLap
        {
            get { return ngayLap; }
            set { ngayLap = value; }
        }
        int tinhTrang;

        public int TinhTrang
        {
            get { return tinhTrang; }
            set { tinhTrang = value; }
        }

        public ArrayList ds_DonHangGui(string emailNguoiGui, int page)
        {
            ArrayList list = new ArrayList();
            SqlConnection conn = KetNoi.Connection();
            SqlCommand cmd = new SqlCommand("SP_DSDONHANGGUI", conn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@EMAILNGUOIGUI", emailNguoiGui);
            cmd.Parameters.AddWithValue("@PAGECURENT", page);
            conn.Open();
            SqlDataReader reader = cmd.ExecuteReader();
            while (reader.Read())
            {
                SP_OrdersSent order = new SP_OrdersSent();
                order.MaDonHang = reader.GetInt32(0);
                order.MaBaoGia = reader.GetInt32(1);
                order.SoLuongDat = reader.GetInt32(2);
                order.Gia = double.Parse(reader.GetDecimal(3).ToString());
                order.TongTien = double.Parse(reader.GetDecimal(4).ToString());
                order.DaTraTruoc = double.Parse(reader.GetDecimal(5).ToString());
                order.EmailNguoiNhan = reader.GetString(6);
                order.NgayLap = reader.GetDateTime(7).ToShortDateString();
                order.TinhTrang = reader.GetInt32(8);
                list.Add(order);
            }
            return list;
        }

        public int sp_TongTrangDHGui(string emailGui)
        {
            int tongdh = 0, tongtrang = 0;
            SqlConnection conn = KetNoi.Connection();
            SqlCommand cmd = new SqlCommand("SP_TONGDONHANGGUI", conn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@EMAILGUI", emailGui);
            conn.Open();
            SqlDataReader reader = cmd.ExecuteReader();
            if (reader.Read())
            {
                tongdh = reader.GetInt32(0);
            }
            tongtrang = tongdh / 10;
            if (tongdh % 10 != 0)
                tongtrang += 1;
            return tongtrang;
        }
    }
}